package com.hyzh.latte.sand.socket.handler;

import com.coffee.socketio.CoffeeSocketioException;
import com.coffee.socketio.handler.CoffeeHandler;
import com.coffee.socketio.handler.SocketioJsonHandler;
import com.corundumstudio.socketio.SocketIOClient;
import com.hyzh.latte.sand.SandClient;
import com.hyzh.latte.sand.SandSessionManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author: songkui
 * @since: 2024/3/21 0:14
 */
@CoffeeHandler("SandCommandType.mtRelay")
@Service
@Slf4j
public class MtRelayHandler implements SocketioJsonHandler {


    @Override
    public void handle(String event, SocketIOClient socketIOClient, String json) throws CoffeeSocketioException {
        SandClient client = SandSessionManager.getInstance().getSandClient(socketIOClient.getSessionId().toString());
        if (null != client){
            SandClient pcClient = SandSessionManager.getInstance().getPcClient(client.getUserId());
            if (null != pcClient){
                pcClient.sendMTMessage(json);
            }
        }else {
            log.error("MT session  is null [pc session : {} ]", socketIOClient.getSessionId());
        }
    }
}
